/*
 * $Header: /opt/javacvs/bk/src/main/java/com/uusee/framework/util/page/PageInfo.java,v 1.1 2009/04/02 10:08:52 wangrui Exp $
 * $Revision: 1.1 $
 * $Date: 2009/04/02 10:08:52 $
 * ============================================================================
 *
 * Copyright (c) 2008 Beijing uusee Tech CO.,  All rights reserved.
 *
 * ============================================================================
 */
package com.uusee.framework.util.page;

import com.uusee.util.PropertiesUtil;

/**
 * 分页信息类
 * 
 * @author duyi
 * 
 * Create Time: 2008-3-26 上午10:09:47
 */
public class PageInfo {

	private int pageSize = 50;

	private int pageNo;

	private int totalPage;

	private long totalResult;

	private int firstResult;

	private int lastResult;

	private boolean onFirstPage;

	private boolean onLastPage;
	
	private int[] pageIndex;
	
	public PageInfo() {
	}

	/**
	 * 判断当前页是否为首页
	 * 
	 * @return
	 */
	public boolean isOnFirstPage() {
		return onFirstPage;
	}

	/**
	 * 设置当前页是否为首页
	 * 
	 * @param onFirstPage
	 */
	public void setOnFirstPage(boolean onFirstPage) {
		this.onFirstPage = onFirstPage;
	}

	/**
	 * 判断当前页是否为末页
	 * 
	 * @return
	 */
	public boolean isOnLastPage() {
		return onLastPage;
	}

	/**
	 * 设置当前页是否为末页
	 * 
	 * @param onFirstPage
	 */
	public void setOnLastPage(boolean onLastPage) {
		this.onLastPage = onLastPage;
	}

	/**
	 * 取页码
	 * 
	 * @return
	 */
	public int getPageNo() {
		return pageNo;
	}

	/**
	 * 设置页码
	 * 
	 * @param pageNo
	 */
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	/**
	 * 取每页显示的实体数量
	 * 
	 * @return
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * 设置每页显示的实体数量
	 * 
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 取总页数
	 * 
	 * @return
	 */
	public int getTotalPage() {
		return totalPage;
	}

	/**
	 * 设总页数
	 * 
	 * @param totalPage
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	/**
	 * 取总记录数
	 * 
	 * @return
	 */
	public long getTotalResult() {
		return totalResult;
	}

	/**
	 * 设总记录数
	 * 
	 * @param totalResult
	 */
	public void setTotalResult(long totalResult) {
		this.totalResult = totalResult;
	}

	/**
	 * 取一页的首记录的位置
	 * 
	 * @return
	 */
	public int getFirstResult() {
		return firstResult;
	}

	/**
	 * 设一页的首记录的位置
	 * 
	 * @param firstResult
	 */
	public void setFirstResult(int firstResult) {
		this.firstResult = firstResult;
	}

	/**
	 * 取一页中最后一条记录的位置
	 * 
	 * @return
	 */
	public int getLastResult() {
		return lastResult;
	}

	/**
	 * 设置一页中最后一条记录的位置
	 * 
	 * @param lastResult
	 */
	public void setLastResult(int lastResult) {
		this.lastResult = lastResult;
	}

	public int[] getPageIndex() {
		int pageIndexStart = 1;
		int pageIndexEnd = totalPage;
		int pageIndexCount = (pageIndexEnd - pageIndexStart)+1;
		if ( pageIndexCount > 0 ) {
			if ( pageIndexCount <= 10 ) {
				pageIndex = new int[pageIndexCount];
				for ( int i = 0; i < pageIndex.length; i++ ) {
					pageIndex[i] = pageIndexStart;
					pageIndexStart++;
				}
			} else {
				pageIndex = new int[10];
				if ( (pageNo-6) <= 2 ) {
					pageIndex[0] =1;
					pageIndex[1] =2;
					pageIndex[2] =3;
					pageIndex[3] =4;
					pageIndex[4] =5;
					pageIndex[5] =6;
					pageIndex[6] =7;
					pageIndex[7] =8;
					pageIndex[8] =9;
					pageIndex[9] =totalPage;
				} else if ( pageNo==totalPage ) {
					pageIndex[0] =1;
					pageIndex[1] =totalPage-8;
					pageIndex[2] =totalPage-7;
					pageIndex[3] =totalPage-6;
					pageIndex[4] =totalPage-5;
					pageIndex[5] =totalPage-4;
					pageIndex[6] =totalPage-3;
					pageIndex[7] =totalPage-2;
					pageIndex[8] =totalPage-1;
					pageIndex[9] =totalPage;
				} else {
					if ( pageNo+1 != totalPage ) {
						pageIndex[0] =1;
						pageIndex[1] =pageNo-6;
						pageIndex[2] =pageNo-5;
						pageIndex[3] =pageNo-4;
						pageIndex[4] =pageNo-3;
						pageIndex[5] =pageNo-2;
						pageIndex[6] =pageNo-1;
						pageIndex[7] =pageNo;
						pageIndex[8] =pageNo+1;	
						pageIndex[9] =totalPage;
					} else {
						pageIndex[0] =1;
						pageIndex[1] =pageNo-7;
						pageIndex[2] =pageNo-6;
						pageIndex[3] =pageNo-5;
						pageIndex[4] =pageNo-4;
						pageIndex[5] =pageNo-3;
						pageIndex[6] =pageNo-2;
						pageIndex[7] =pageNo-1;
						pageIndex[8] =pageNo;	
						pageIndex[9] =totalPage;	
					}
									
				}			
			}
			
			
		}
		return pageIndex;
	}

	public void setPageIndex(int[] pageIndex) {
		this.pageIndex = pageIndex;
	}
	
	
	
	
}
